﻿// Learn more about F# at http://fsharp.net

open System 

open FsCheck
open FsCheck.Arb
open FsCheck.Prop
open FsCheck.Gen

open Lilium.LParse
open Lilium.LParse.Prelude

Check.Quick
    ( "satisfy"
    , fun (a : char) (b : char) ->
        let parser = Parser.satisfy (a.Equals)
        let result = Parser.unParser parser [b]
        match result with
        | (x,[])::[] when a = b -> true
        | [] when a <> b -> true
        | _ -> false )


Check.Quick
    ( "Lilium.LParse.HistoryParser.satisfy"
    , fun (a : char) (b : char) ->
        let parser = HistoryParser.satisfy (a.Equals)
        let (h, v) = HistoryParser.parse parser (State.fromList [b])
        match h, v with
        | _, a when a = b -> true
        | _, _ when a <> b -> true
        | _ -> false )

Check.Quick
    ( "Lilium.LParse.HistoryParser.compose"
    , fun (a : char) (b : char) ->
        let p1 = HistoryParser.satisfy (a.Equals)
        let p1' = HistoryParser.apply (fun a b -> [a;b]) p1
        let p2 = HistoryParser.satisfy (b.Equals)
        let p = HistoryParser.compose p1' p2
        let (h, v) = HistoryParser.parse p  (State.fromList [a;b])
        v = [a;b] )